package middlewares

import (
	"net/http"

	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
)

func AuthMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		token := c.GetHeader("Authorization")

		if token == "" {
			logrus.Errorf("token is empty")
			c.JSON(http.StatusUnauthorized, gin.H{"error": "Authorization header is required"})
			c.Abort()
			return
		}
		// 鉴权 token
		/*
		_, err := tokenVerify(token)
		if err != nil {
			logrus.Errorf("tokenVerify(%s) err: %s", token, err.Error())
			c.JSON(http.StatusUnauthorized, gin.H{"error": "Invalid authorization token"})
			c.Abort()
			return
		}
		*/

		// 继续处理请求
		c.Next()
	}
}